<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" href="../../css/mui.min.css">
<link rel="stylesheet" href="../../css/base.css">
<script src="../../script/api.js" type="text/javascript"></script>
<script src="../../script/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>

<script src="../../script/ui.js"></script>
<style>
    .msg_content {
        width: 70%;
        padding-top: 15px;
        padding-left: 10px;
        color: #222222;
        font-size: 18px;
        /*vertical-align: middle;*/
    }

    .companyTeacher {
        border: 1px solid #9AC8E5;
        font-size: 14px;
        color: #9AC8E5;
        line-height: 14px;
        padding: 4px;
        vertical-align: middle;
    }

    .mui-pull-left img {
        width: 40px;
    }

    .base_add_icon {
        height: 22px;
        float: right;
        margin-right: 15px;
        margin-top: 10px;
    }
</style>
<body>
<div id='BarAppearance'></div>
<div class="base_navigation_bar base_style_color">
    <a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon"
                                                                   src="../../image/icon_jiantou.png" alt=""> </a>
    <span id="nav_title">群名称</span>
    <a class="base_right_item nav-item" href="#" onclick="groupPeople(false)" id="scan_div"> <img class="base_add_icon"
                                                                                                  src="../../image/chat/ring_people.png"
                                                                                                  alt=""> </a>
</div>

</body>
</html>
<script>
    var conversationId;
    var conversationPeopleList;
    apiready = function () {
        conversationId = api.pageParam.conversationId;
        if (api.pageParam.openType) {
            //从其他入口直接进入课堂详情
            loginHuanxing();
        }
        $('#nav_title').html(api.pageParam.conversationName);
        initHeaderUI();
        initData();
        api.addEventListener({
            name: 'selectPeople'
        }, function (ret, err) {
            groupPeople(true);
        });
    }

    function initData() {
        cfnetppPOST(url_ring_people,{"group_id":conversationId}, false, function (data, status) {
            if (data.status) {
                conversationPeopleList = data.data.list;
                openFrame();

            }
        })
    }

    function loginHuanxing() {
        var easeChat = api.require('easeChat');
        easeChat.login({
            username: $api.getStorage('cfRingUsername'),
            password: $api.getStorage('cfRingPassword'),
            autoLogin: true
        }, function (ret, err) {
            // initData();
            console.log("环信登录结果:" + JSON.stringify(ret));
            if (ret.status) {
                register();
            } else {
                api.toast({msg: "消息登录失败"});
            }
        });
    }

    function register() {
        //关闭消息推送
        var easeChat = api.require('easeChat');
        if (api.systemType === 'ios') {
            easeChat.setLocalNotification({
                enable: false,
                title: '您有一条新的消息'
            });
        }

        //注册消息监听
        easeChat.addAccountListener(function (ret) {
            console.log("账号异常登录");
            api.alert({msg: "您的账号在其他位置登录"});
            api.closeToWin({
                name: 'index'
            });
        });
        //todo 环信消息接收监听
        easeChat.addMessageListener({
            name: 'receive'
        }, function (ret) {
            api.sendEvent({
                name: 'ringmessage',
                extra: {
                    message: ret.messages,
                }
            });
        });
    }

    function openFrame() {
        var rect = {
            x: 0,
            y: $('#BarAppearance').height() + $('.base_navigation_bar').height(),
            w: 'auto',
            h: 'auto'
        };
        api.openFrame({
            name: 'circleChat',
            url: 'circleChat.html',
            // url: 'http://www.baidu.com',
            bounces: false,
            rect: rect,
            allowEdit: true,
            pageParam: {
                conversationId: conversationId,
                conversationPeopleList: conversationPeopleList,
                effective_state: api.pageParam.effective_state
            },
            progress: {//设置进度条类型和样式
                type: 'page',
                color: '#18b4ed'
            }
        });

    }

    function groupPeople(canSelected) {
        api.openWin({useWKWebView:true,
            name: 'chatGroupPeople',
            url: 'chatGroupPeople.html',
            pageParam: {
                isCanSelected: canSelected,
                conversationPeopleList: conversationPeopleList
            }
        });
    }

    function backClick() {
        api.closeWin();
    }
</script>